-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apply transverse aperture to thick elements. #788
base: development
Are you sure you want to change the base?
Conversation
Add namespace amrex::literals
Add Python class for aperture mixin.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Note: Windows test fail now, but all tests were previously passing. |
src/particles/elements/Drift.H
Outdated
amrex::ParticleReal xmax = 0, | ||
amrex::ParticleReal ymax = 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if for all potential elements, xmax
and ymax
are general enough argument names.
They do make sense for the Aperture
element, but for all other thick elements we might need something more specific, e.g., x_open
or x_aperture
?
Another small change I thought we could do is use std::optional<amrex::ParticleReal> ... = std::nullopt
. That way, we do not redefine 0
with a jump, which technically is a fully blocking aperture. The equivalent in Python is then x_aperture = None
, which is clearly no aperture.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like x_aperture
, and I'll make that change. Will look into using std::optional
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To get the value out of std::optional, call operator* or .value().
We will need to write the real value into m_x_aperture
because we cannot (should not) use std::optional
on GPU. For no value, I would maybe write a negative value into the member variable and only apply the aperture for >=0. That way, 0 is well-defined (blocking).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify the last comment: We're avoiding std::optional
altogether? If so, I actually prefer the existing approach, to apply the aperture when x_aperture > 0 and y_aperture >0. Why? 1) Allowing for blocking with x_aperture = 0 requires changing the logic/math in the mixin class, 2) A thick element with zero aperture has no use case (eg, its action is the same as a thin screen for blocking), 3) Allowing this case means setting the default values of x_aperture, y_aperture to an arbitrarily-chosen negative number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, then we can keep it simple and document <= zero as no-aperture 👍
Small changes (excluding naming and std::optional). Co-authored-by: Axel Huebl <[email protected]>
Remove "maybe unused".
Problems on Windows after merging in 'development'... |
for more information, see https://pre-commit.ci
* ``<element_name>.aperture_x`` (``float``, in meters) horizontal half-aperture (elliptical or rectangular) | ||
* ``<element_name>.aperture_y`` (``float``, in meters) vertical half-aperture (elliptical or rectangular) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, breaking change for existing aperture
element users.
Not necessarily needed for this PR to work, but we can make it work by adding a bit more logic to transition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree. The case for consistent naming is pretty strong. One of the main aperture
users is @SchroederSa, who was the first to suggest that xmax
and ymax
were not the best names. Did you have in mind to support both input syntax by modifying InitElement.cpp
and python/elements.cpp
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll add a fallback to make the transition easier there.
src/initialization/InitElement.cpp
Outdated
pp_element.get("aperture_x", aperture_x); | ||
pp_element.get("aperture_y", aperture_y); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to rename the parameter (not needed for this PR), then I would add a bool has_xmax = pp_element.query("xmax", xmax);
then if true, throw a warning and set the value for aperture_x
(unless that one is set as well). Same for y.
But as I said, I don't think we need to rename the Aperture
arguments with this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still have to add this part.
py::arg("aperture_x"), | ||
py::arg("aperture_y"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above: we could avoid this breaking change for the Aperture
element itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The break of API arg name here might be ok, for python people might not use the named arguments yet that much.
We do not want to create variables from them.
Mirror directory structure and separate from "physical" elements as we do in Python.
Adds the comparison of particles against the transverse aperture within thick elements, at the end of each space charge slice. This will close #763 .
Note: Need to verify that using the same name
Aperture
for the thin aperture element and for the mixin class will not cause conflicts. Otherwise, one of these should be renamed.Aperture
constructor non-breaking with warnings